#include<bits/stdc++.h>
#define int long long
using namespace std;
const int mod=1e9+7;
int ksm(int x,int y){
	long long res=1,now=x;
	while(y){
		if(y&1) res*=now;
		now*=now,y>>=1;
	}
	return res;
}
int T,a,b,c;
signed main(){
	freopen("alien.in","r",stdin);
	freopen("alien.out","w",stdout);
	scanf("%lld",&T);
	while(T--){
		scanf("%lld%lld%lld",&a,&b,&c);
		int ans=0;
		for(int i=1;i<=a;i++)
			for(int j=1;j<=b;j++)
				for(int k=1;k<=c;k++)
					if(ksm(j,i)==ksm(i,k)) ans++,ans%=mod;
		printf("%lld\n",ans);
	}
	return 0;
}
